package com.eastfair.builder.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.request.PageParams;
import com.eastfair.builder.service.BuilderServiceBookingService;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.venueservice.dto.ServiceBookingDTO;
import com.eastfair.venueservice.dto.ServiceBookingQuery;
import com.eastfair.venueservice.dto.ServiceBookingUpdateDTO;
import com.eastfair.venueservice.vo.ServiceBookingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * <p>
 * 前端控制器
 * 搭建商服务预订
 * </p>
 *
 * @author dq
 * @date 2022-08-06
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/builderServiceBooking")
@Api(value = "BuilderServiceBooking", tags = "搭建商服务预订")
@PreAuth(replace = "builder:builderServiceBooking:")
public class BuilderServiceBookingController{

    @Resource
    private BuilderServiceBookingService builderServiceBookingService;

    /**
     * 添加服务预订
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "添加服务预订")
    @SysLog("添加服务预订")
    @PostMapping(value = "/addServiceBooking")
    public R<Boolean> addServiceBooking(@RequestBody @Validated @NotEmpty List<ServiceBookingDTO> serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.addServiceBooking(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 添加服务预订（报馆后预订的服务）
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "添加服务预订（报馆后预订的服务）")
    @SysLog("添加服务预订")
    @PostMapping(value = "/addServiceBookingAfterReport")
    public R<Boolean> addServiceBookingAfterReport(@RequestBody @Validated @NotEmpty List<ServiceBookingDTO> serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.addServiceBookingAfterReport(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 提交服务预订
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "保存服务预订")
    @SysLog("添加服务预订")
    @PostMapping(value = "/saveServiceBooking")
    public R<Boolean> saveServiceBooking(@RequestBody @Validated @NotEmpty List<ServiceBookingDTO> serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.saveServiceBooking(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 删除预定服务
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "删除预定服务")
    @SysLog("删除服务预订")
    @PostMapping(value = "/delServiceBooking")
    public R<Boolean> delServiceBooking(@RequestBody ServiceBookingDTO serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.delServiceBooking(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 取消预定服务
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "取消预定服务")
    @SysLog("取消服务预订")
    @PostMapping(value = "/cancelServiceBooking")
    public R<Boolean> cancelServiceBooking(@RequestBody ServiceBookingUpdateDTO serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.cancelServiceBooking(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 服务预订列表
     *
     * @param serviceBookingQuery 服务预订列表
     * @return R
     */
    @ApiOperation(value = "服务预订列表", notes = "服务预订列表")
    @PostMapping("/queryServiceBookingList")
    public R<List<ServiceBookingVO>> queryServiceBookingList(@RequestBody ServiceBookingQuery serviceBookingQuery) {
        log.info("queryServiceBookingList - 服务预订列表 serviceBookingQuery={}", serviceBookingQuery);
        return R.success(builderServiceBookingService.queryServiceBookingList(serviceBookingQuery));
    }


    /**
     * 回填预订服务的审核结果
     * @param serviceBookingDTO serviceBookingDTO
     * @return R<Boolean>
     */
    @ApiOperation(value = "回填预订服务的审核结果")
    @PostMapping(value = "/updateServiceBookingAuditResult")
    public R<Boolean> updateServiceBookingAuditResult(@RequestBody List<ServiceBookingDTO> serviceBookingDTO){
        try {
            return R.success(builderServiceBookingService.updateServiceBookingAuditResult(serviceBookingDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 报馆提交服务预订
     * @param reportSpaceId 报馆ID
     * @param reportSpaceAuditId 报馆审核ID
     * @return R<Boolean>
     */
    @ApiOperation(value = "报馆提交服务预订")
    @GetMapping(value = "/submitServiceBookingWhenReport")
    public R<Boolean> submitServiceBookingWhenReport(@RequestParam("reportSpaceId") Long reportSpaceId, @RequestParam("reportSpaceAuditId") Long reportSpaceAuditId) {
        try {
            return R.success(builderServiceBookingService.submitServiceBookingWhenReport(reportSpaceId,reportSpaceAuditId));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }


    /**
     * 服务预订管理列表
     *
     * @param serviceBookingQuery 服务预订管理列表
     * @return R
     */
    @ApiOperation(value = "服务预订管理列表", notes = "服务预订管理列表")
    @PostMapping("/queryServiceBookingManage")
    public R<IPage<ServiceBookingVO>> queryServiceBookingManage(@RequestBody PageParams<ServiceBookingQuery> serviceBookingQuery){
        log.info("queryServiceBookingManage - 服务预订管理列表 serviceBookingQuery={}", serviceBookingQuery);
        return R.success(builderServiceBookingService.queryServiceBookingManage(serviceBookingQuery));
    }

    /**
     * 主场一键报馆的全部服务
     *
     * @param serviceBookingQuery 主场一键报馆的全部服务
     * @return R
     */
    @ApiOperation(value = "主场一键报馆的全部服务", notes = "主场一键报馆的全部服务")
    @PostMapping("/queryServiceBookingOfHome")
    public R<Page<ServiceBookingVO>> queryServiceBookingOfHome(@RequestBody PageParams<ServiceBookingQuery> serviceBookingQuery){
        log.info("queryServiceBookingOfHome - 主场一键报馆的全部服务 serviceBookingQuery={}", serviceBookingQuery);
        return R.success(builderServiceBookingService.queryServiceBookingOfHome(serviceBookingQuery));
    }

    /**
     * 主场一键报馆服务
     * @param serviceBookingDTO 主场一键报馆服务
     * @return R<Boolean>
     */
    @ApiOperation(value = "主场一键报馆服务")
    @PostMapping(value = "/submitServiceBookingToVenue")
    public R<Boolean> submitServiceBookingToVenue(@RequestBody List<ServiceBookingDTO> serviceBookingDTO){
        log.info("submitServiceBookingToVenue - 主场一键报馆服务 serviceBookingDTO={}", serviceBookingDTO);
        return R.success(builderServiceBookingService.submitServiceBookingToVenue(serviceBookingDTO));
    }
}
